package com.scqzy.shengchunqiang.sword2offer.day05;

/**
 * @Description: 剑指 Offer 04. 二维数组中的查找
 * @Author 盛春强
 * @Date 2021/8/12 20:22
 */
public class FindNumberIn2DArray {
    public boolean findNumberIn2DArray(int[][] matrix, int target) {
        for (int[] nums : matrix) {
            int left = 0;
            int right = nums.length - 1;
            while (left <= right) {
                int mid = (left + right) / 2;
                if (target < nums[mid]) {
                    right = mid - 1;
                } else if (target > nums[mid]) {
                    left = mid + 1;
                } else {
                    return true;
                }
            }
        }
        return false;
    }
}
